import ulOption from '../time-option'
export default {
  name: 'SiderBav',
  props: {
    options: {
      type:Object,
      default () {
        return {
        	 name:'',
        	 id:'',
        	 workday:[],
        	 weekend:[]
        }
      }
    }
  },
  components:{
  	ulOption
  },
  data () {
  	 return {
  	 	  workday:[],
  	 	  weekend:[],
  	 	  orSaveTem:false,
  	 	  updateId:'',
  	 	  data:{
  	 	  	  name:'',
  	 	  	  workday:[],
  	 	  	  weekend:[]
  	 	  }
  	 }
  },
  watch:{
  	 options(val)
  	 {
  	 	   this.data.name=val.name;
  	 	   this.updateId=val.id;
  	 	   this.updateId?(this.orSaveTem=true):''
  	 	   this.workday=val.workday;
  		   this.weekend=val.weekend;
  	 }
  },
  methods:{
  	empty(){
  		  this.workday=[];
  		  this.weekend=[];
  	},
  	timeTemChange15(val){
  		 if(val){
  		 	  this.data.workday=val
  		 }
  	},
  	timeTemChange67(val){
  		if(val){
  		 	  this.data.weekend=val
  		 }
  	},
  	saveTimeTem()
  	{
  		if(this.data.name=='')
  		{
  			  this.n3Toast({
			        text: '模板名称不能为空',
			        type: 'dranp',
			        placement: 'top',
			        closeOnClick : true
			      });
  				return false;
  		}
  		let url=this.updateId?'/zuanzhan/put-time/update':'/zuanzhan/put-times';
  		this.updateId?(this.data['id']=this.updateId):(this.data['id']=undefined);
  		 this.$http.post(url,this.data).then((data)=>{
	  		  	if(!this.$http.interceptors(this,data))return;
	  		  	this.n3Toast({
			        text: '模板保存成功',
			        type: 'success',
			        placement: 'top',
			        closeOnClick : true
			     });
			     this.$emit('input',this.data);
			     this.$emit('change',this.data);
  		  })
			  .catch(function (error) {
			    console.log(error);
			  });
  	}
  }
}